package hr.fer.zemris.EvolutionOps;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.uncommons.maths.random.Probability;
import org.uncommons.watchmaker.framework.EvolutionaryOperator;

public class MutationOperator<T> implements EvolutionaryOperator<T> {
	private Probability probability;
	private IMutator<T> mutator;
	
	public MutationOperator(IMutator<T> mutator, Probability probability) {
		this.probability = probability;
		this.mutator = mutator;
	}
	@Override
	public List<T> apply(List<T> selectedCandidates, Random rnd) {
		List<T> ret = new ArrayList<T>();
		probability.nextEvent(rnd);
		for (T individual : selectedCandidates) {
			ret.add(mutator.mutate(individual, probability, rnd));
		}
		return ret;
	}

}
